package com.aiti.lulian.controller.gongxin;

import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.gxmh.dto.GxmhMessageUserDto;
import com.aiti.lulian.gxmh.service.IGxmhMessageUserService;
import com.aiti.lulian.gxmh.vo.GxmhMessageUserVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "工信门户-消息用户控制层")
@RestController
@RequestMapping("/gxmhMsgUser")
public class GxmhMessageUserController extends WebController {

    @Autowired
    private IGxmhMessageUserService gxmhMessageUserService;

    @ApiOperation("查询收到的消息列表")
    @GetMapping("/list")
    public Message getMyMessageList(GxmhMessageUserDto dto) {
        Page page = startPage();
        List<GxmhMessageUserVo> list = gxmhMessageUserService.getMyMessageList(page, dto);
        return Message.success(getPageResult(list, dto.getPageNum(), dto.getPageSize(), page.getTotal()));
    }

    @ApiOperation("查询收到的消息详情")
    @GetMapping("/details")
    public Message getMyMessageDetails(@RequestParam("userId") String userId,
                                       @RequestParam("messageId") String messageId) {
        return Message.success(gxmhMessageUserService.getMyMessageDetails(userId, messageId));
    }

    @ApiOperation("查询未读消息数")
    @GetMapping("/unread/getCount")
    public Message getUnreadCount(@RequestParam("userId") String userId) {
        return Message.success(gxmhMessageUserService.getUnreadCount(userId));
    }

    @ApiOperation("已读消息")
    @PutMapping
    public Message readMessage(@RequestBody GxmhMessageUserDto dto) {
        return gxmhMessageUserService.readMessage(dto);
    }
}
